package com.gtw;

import com.gtw.interpreter.Context;

import java.util.HashMap;

public class Client {
    public static void main(String[] args) {
        //百以内加减法
        String expStr = "a+b+c-d";
        HashMap<String, Integer> var = getValue(expStr);
        Context context = new Context(expStr);
        System.out.println(expStr + "运算结果:" + context.run(var));
    }

    // 给a,b,c,d赋值
    private static HashMap<String,Integer> getValue(String expStr) {
        HashMap<String, Integer> var = new HashMap<String, Integer>();
        for(char ch : expStr.toCharArray()){
            if(ch != '+' && ch != '-'){
                //解决参数重复的问题
                if(!var.containsKey(String.valueOf(ch))){
                    int value = (int)(Math.random()*100);
                    System.out.println(ch + " : " + value);
                    var.put(String.valueOf(ch), value);
                }
            }
        }
        return var;
    }
}
